package com.ate.app2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends AppCompatActivity {

    private RelativeLayout rela;
    private TextView djs;
    private Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        initView();


    }

    private void initView() {
        rela = (RelativeLayout) findViewById(R.id.rela);
        rela.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                timer.cancel();
                startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
            }
        });
        djs = (TextView) findViewById(R.id.djs);
        djstime();
    }
    int time=4;
    private void djstime() {
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        djs.setText(--time+"");
                        if (time<=0){
                            startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
                            timer.cancel();
                        }
                    }
                });
            }
        },0,1000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}